<script lang="ts" setup>
import { ref } from 'vue'
// import { useSafeAreaHooks } from '@/composables/useSafeArea'

// const { top } = useSafeAreaHooks()

const currentTab = ref(0)
const tabs = ref([
  { name: '笔记' },
  { name: '收藏' },
  { name: '赞过' },
])
const contentList = ref([
  {
    image: 'https://ai-public.mastergo.com/ai/img_res/ede217be271173a7559e302a85d972f9.jpg',
    title: '周末探店|超治愈的手冲咖啡店',
    likes: '2.8k',
    comments: '164',
  },
  {
    image: 'https://ai-public.mastergo.com/ai/img_res/c21553356cab78c4b7dd42ad3c93e10d.jpg',
    title: '超详细甜点制作教程',
    likes: '3.2k',
    comments: '258',
  },
  {
    image: 'https://ai-public.mastergo.com/ai/img_res/39e2a555a7ea5d3d65fc42947902c7b9.jpg',
    title: '周末出行|看最美的日落',
    likes: '5.6k',
    comments: '426',
  },
  {
    image: 'https://ai-public.mastergo.com/ai/img_res/c21553356cab78c4b7dd42ad3c93e10d.jpg',
    title: '测试数据的标题',
    likes: '1.2k',
    comments: '58',
  },
  {
    image: 'https://ai-public.mastergo.com/ai/img_res/ede217be271173a7559e302a85d972f9.jpg',
    title: '手冲咖啡店',
    likes: '0.8k',
    comments: '14',
  },
  {
    image: 'https://ai-public.mastergo.com/ai/img_res/39e2a555a7ea5d3d65fc42947902c7b9.jpg',
    title: '周末出行',
    likes: '25.6k',
    comments: '426',
  },
])
function switchTab(index: number) {
  currentTab.value = index
}

function handleEdit() {
  // 处理编辑资料的点击事件
}
</script>

<template>
  <view class="profile-container">
    <!-- 滚动区域 -->
    <scroll-view
      class="scroll-area"
      scroll-y
    >
      <!-- 顶部个人信息区 -->
      <view class="header-section">
        <view class="cover-image">
          <image
            src="https://ai-public.mastergo.com/ai/img_res/089504f6f66860433a9bf49157487b56.jpg"
            mode="aspectFill"
          />
        </view>
        <view class="profile-info">
          <image
            class="avatar"
            src="https://p.ssl.qhimg.com/sdm/480_480_/t01ae81c6959c497192.jpg"
            mode="aspectFill"
          />
          <view class="user-info">
            <view>
              <view class="info-header">
                <view class="name-wrap">
                  <text class="nickname">
                    晨曦向暖
                  </text>
                  <uni-icons
                    type="checkmarkempty"
                    size="16"
                    color="#007AFF"
                  />
                </view>
              </view>
              <text class="signature">
                分享生活，发现美好
              </text>
            </view>
            <wd-button
              type="info"
              @click="handleEdit"
            >
              编辑资料
            </wd-button>
          </view>
          <view class="stats-bar">
            <view class="stat-item">
              <text class="num">
                328
              </text>
              <text class="label">
                关注
              </text>
            </view>
            <view class="stat-item">
              <text class="num">
                12.8k
              </text>
              <text class="label">
                粉丝
              </text>
            </view>
            <view class="stat-item">
              <text class="num">
                45.2k
              </text>
              <text class="label">
                获赞
              </text>
            </view>
          </view>
        </view>
      </view>
      <!-- 内容分类导航 -->
      <view class="tab-section">
        <view class="tab-header">
          <view
            v-for="(tab, index) in tabs"
            :key="index"
            class="tab-item"
            :class="{ active: currentTab === index }"
            @click="switchTab(index)"
          >
            <text>{{ tab.name }}</text>
          </view>
        </view>
        <!-- 内容展示区 -->
        <view class="content-section">
          <view class="waterfall">
            <view
              v-for="(item, index) in contentList"
              :key="index"
              class="content-card"
            >
              <image
                :src="item.image"
                mode="widthFix"
              />
              <view class="card-info">
                <text class="title">
                  {{ item.title }}
                </text>
                <view class="interaction">
                  <view class="like">
                    <uni-icons
                      type="heart"
                      size="16"
                    />
                    <text>{{ item.likes }}</text>
                  </view>
                  <view class="comment">
                    <uni-icons
                      type="chatbubble"
                      size="16"
                    />
                    <text>{{ item.comments }}</text>
                  </view>
                </view>
              </view>
            </view>
          </view>
        </view>
      </view>
    </scroll-view>
  </view>
</template>

<style lang="less" scoped>
.profile-container {
  height: 100%;
  display: flex;
  flex-direction: column;
  background-color: #fff;
}

.scroll-area {
  flex: 1;
  overflow: auto;
}

.header-section {
  position: relative;
}

.cover-image {
  width: 750rpx;
  height: 460rpx;
}

.cover-image image {
  width: 100%;
  height: 100%;
}

.profile-info {
  margin-top: -100rpx;
  padding: 0 30rpx;
}

.avatar {
  width: 160rpx;
  height: 160rpx;
  border-radius: 80rpx;
  border: 4rpx solid #ffffff;
}

.user-info {
  margin-top: 20rpx;
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
}

.name-wrap {
  display: flex;
  align-items: center;
  gap: 8rpx;
}

.nickname {
  font-size: 32px;
  font-weight: 600;
  color: #333333;
}

.signature {
  font-size: 14px;
  color: #666666;
  margin-top: 8rpx;
}

.stats-bar {
  display: flex;
  margin-top: 30rpx;
  padding: 20rpx 0;
}

.stat-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.stat-item .num {
  font-size: 16px;
  font-weight: 600;
  color: #333333;
}

.stat-item .label {
  font-size: 12px;
  color: #999999;
  margin-top: 4rpx;
}

.action-bar {
  display: flex;
  align-items: center;
  padding: 30rpx;
  gap: 16rpx;
}

.action-bar .uni-button {
  flex: 1;
  margin: 0;
  height: 72rpx;
  line-height: 72rpx;
  font-size: 14px;
  border-radius: 36rpx;
}

.edit-profile {
  display: inline-flex;
  align-items: center;
  padding: 12rpx 24rpx;
  background: #f8f9fa;
  border-radius: 32rpx;
  margin-top: 16rpx;
  transition: all 0.3s ease;
}

.edit-profile:active {
  background: #f0f1f2;
}

.edit-text {
  font-size: 13px;
  color: #666666;
  margin-left: 8rpx;
}

.tab-section {
  background-color: #ffffff;
}

.tab-header {
  display: flex;
  padding: 0 30rpx;
  border-bottom: 1px solid #f0f0f0;
}

.tab-item {
  flex: 1;
  display: flex;
  justify-content: center;
  padding: 20rpx 0;
  font-size: 14px;
  color: #666666;
}

.tab-item.active {
  color: #333333;
  font-weight: 600;
  position: relative;
}

.tab-item.active::after {
  content: '';
  position: absolute;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 40rpx;
  height: 4rpx;
  background-color: #FE2C55;
  border-radius: 2rpx;
}

.content-section {
  padding: 20rpx;
  background-color: #f8f8f8;
}

.waterfall {
  column-count: 2;
  column-gap: 20rpx;

  .content-card {
    break-inside: avoid;
    background-color: #ffffff;
    border-radius: 16rpx;
    overflow: hidden;
    box-shadow: 0 2rpx 16rpx rgba(0, 0, 0, 0.04);
    margin-bottom: 20rpx;

    image {
      width: 100%;
    }
  }
}

.card-info {
  padding: 20rpx;
}

.card-info .title {
  font-size: 14px;
  color: #333333;
  line-height: 1.4;
  margin-bottom: 16rpx;
}

.interaction {
  display: flex;
  gap: 30rpx;
}

.like,
.comment {
  display: flex;
  align-items: center;
  gap: 8rpx;
  color: #999999;
  font-size: 12px;
}

.tab-bar {
  display: flex;
  height: 100rpx;
  background-color: #ffffff;
  border-top: 1px solid #f0f0f0;
}

.tab-bar-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  color: #666666;
  gap: 4rpx;
}

.tab-bar-item.active {
  color: #FE2C55;
}
</style>
